package com.base.cn.platform.os.controller.manage.group;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.manage.group.SysGroup;
import com.base.cn.platform.os.service.manage.group.SysGroupBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 部门Controller接口
 *
 * @author s.li
 * @create 2018-04-03-10:38
 */
@RestController
@RequestMapping("/manage")
public class SysGroupController extends BaseController {

    @Autowired
    private SysGroupBiz sysGroupBiz;

    /**
     * 保存部门数据信息
     * @param sysGroup 部门数据对象
     * @return Map<String,Object>
     */
    @RequestMapping("/saveSysGroup")
    public Map<String,Object> saveSysGroup(@RequestBody SysGroup sysGroup){
        if(StringUtils.isEmpty(sysGroup.getGroupName())){
            return ResultUtil.ERROR("请填写部门名");
        }
        if(sysGroup.getGroupName().trim().length()>30){
            return ResultUtil.ERROR("部门名限制在30个字以内");
        }
        if(StringUtils.isNotEmpty(sysGroup.getDepict()) && sysGroup.getDepict().trim().length()>500){
            return ResultUtil.ERROR("部门描述是对于该部门的具体说明内容限制在500个字以内");
        }
        sysGroup = sysGroupBiz.saveSysGroup(sysGroup);
        return ResultUtil.SUCCESS("部门信息保存成功",sysGroup);
    }

    /**
     * 查询部门列表，（分层）
     * @param sysGroup 查询条件
     * @return  List<SysGroup>
     */
    @RequestMapping("/findLayeredSysGroupList")
    public List<SysGroup> findLayeredSysGroupList(@RequestBody SysGroup sysGroup){
        return sysGroupBiz.findLayeredSysGroupList(sysGroup);
    }


    /**
     * 查询部门列表
     * @param sysGroup 查询对象
     * @return List<SysGroup>
     */
    @RequestMapping("/findSysGroupList")
    public List<SysGroup> findSysGroupList(@RequestBody SysGroup sysGroup){
        return sysGroupBiz.findSysGroupList(sysGroup);
    }

    /**
     * 通过ID查询部门对象
     * @param id 部门ID
     * @return  SysGroup
     */
    @RequestMapping("/findSysGroupById")
    public SysGroup findSysGroupById(@RequestParam("id") BigDecimal id){
        return sysGroupBiz.findSysGroupById(id);
    }

    /**
     * 修改部门状态
     * @param ids 部门ID串
     * @param status 状态，1正常，2禁用，3删除
     * @return Map<String,Object>
     */
    @RequestMapping("/updateSysGroupStatus")
    public Map<String,Object> updateSysGroupStatus(@RequestParam("ids") String ids,@RequestParam("status") int status){
        sysGroupBiz.updateSysGroupStatus(ids,status);
        return ResultUtil.SUCCESS("部门状态修改成功");
    }

    /**
     * 修改部门的父级归属
     * @param id 部门ID
     * @param parentId 部门父ID
     */
    @RequestMapping("/updateSysGroupParentId")
    public Map<String,Object> updateSysGroupParentId(@RequestParam("id")BigDecimal id,
                                                     @RequestParam("parentId") BigDecimal parentId){
        sysGroupBiz.updateSysGroupParentId(id,parentId);
        return ResultUtil.SUCCESS("移动部门父级归属成功");
    }
}
